# Maintainer: Tim Meusel <tim@bastelfreak.de>

_gemname='minitest-retry'
pkgname="ruby-${_gemname}"
pkgver=0.2.2
pkgrel=1
pkgdesc='re-run the test when the test fails'
arch=('any')
url='https://github.com/y-yagi/minitest-retry'
license=('MIT')
depends=('ruby' 'ruby-minitest')
makedepends=('ruby-rake' 'ruby-bundler')
checkdepends=()
options=('!emptydirs')
source=("${url}/archive/v${pkgver}/${_gemname}-v${pkgver}.tar.gz")
sha512sums=('c49620387999894742fb92a399440756eac046f7aa179dbf084e77cc2a43260bff7f5d012c2140062da8785b9592bedf6e6b38692fbd7753dd3d15fc5ca932a1')

prepare() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  # allow latest dependencies
  sed --in-place 's|`git ls-files -z`|`find . -print0`|' "${_gemname}.gemspec"

  # drop useless dependency
  sed --in-place '/bundler/d' Rakefile "${_gemname}.gemspec"
  sed --in-place '/pry/d' Gemfile test/test_helper.rb
}

build() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  gem build "${_gemname}.gemspec"
}

check() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  rake test
}

package() {
cd "${srcdir}/${_gemname}-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --verbose --ignore-dependencies --no-user-install --install-dir "${pkgdir}/${_gemdir}" --bindir "${pkgdir}/usr/bin" "${_gemname}-${pkgver}.gem"

  install -Dm 644 LICENSE.txt -t "${pkgdir}/usr/share/licenses/${pkgname}/"

  install -Dm 644 README.md CHANGELOG.md -t "${pkgdir}/usr/share/doc/${pkgname}"

  rm -rf "${pkgdir}/${_gemdir}/cache"
 }
